package cn.ffcs.uec.post.component;

import lombok.Getter;
import lombok.Setter;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Bandbox;

import cn.ffcs.uec.post.component.bean.UecPostBandboxExtBean;
import cn.ffcs.uec.post.model.UecPost;

@Controller
@Scope("prototype")
public class UecPostBandboxExt extends Bandbox implements IdSpace {
	private static final long serialVersionUID = 7932446699171801059L;

	/**
	 * 页面对应的bean
	 */
	@Getter
	@Setter
	private UecPostBandboxExtBean bean = new UecPostBandboxExtBean();

	/**
	 * 页面zul
	 */
	public static final String zul = "/pages_nmg/uec_post/comp/uec_post_bandbox_ext.zul";

	private UecPost uecPost;
	
	private UecPostListboxExt uecPostListboxExt;

	/**
	 * 初始化
	 */
	public UecPostBandboxExt() {
		Executions.createComponents(zul, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');

		// 1、先获取控件
		uecPostListboxExt = (UecPostListboxExt) this.getFellow("uecPostListboxExt");
		// 2、中转：转换监听的事件与处理事件的方法名
		uecPostListboxExt.addForward("onSelectUecPost", this, "onSelectUecPostResponse");
	}

	/**
	 * 监听事件listbox选中记录事件
	 * 
	 * @param event
	 */
	public void onSelectUecPostResponse(final ForwardEvent event) {
		uecPost = (UecPost) event.getOrigin().getData();
		if (null != uecPost) {
			setValue(uecPost.getPostname());
			this.close();
		}
		Events.postEvent("onUecPostEditSelected",this, uecPost);
	}

	/**
	 * 点击”确认“按钮事件
	 */
	public void onClick$okButton() {
		this.close();
	}

	/**
	 * 点击“取消”按钮事件
	 */
	public void onClick$cancelButton() {
		this.close();
	}

}
